package com.mdd.front.controller;

import com.mdd.common.aop.NotLogin;
import com.mdd.common.aop.NotPower;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.front.service.IRegionService;
import com.mdd.front.vo.region.RegionDetailVo;
import com.mdd.front.vo.region.RegionListedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("api/region")
@Api(tags = "地区管理")
public class RegionController {

    @Resource
    IRegionService iRegionService;


    @NotLogin
    @GetMapping("/detail")
    @ApiOperation(value="地区详情")
    public AjaxResult<RegionDetailVo> detail(@Validated @IDMust() @RequestParam("id") Long id) {
        RegionDetailVo detail = iRegionService.detail(id);
        return AjaxResult.success(detail);
    }


    @NotLogin
    @GetMapping("/listFirst")
    @ApiOperation(value="获取一级地区")
    public AjaxResult<List<RegionListedVo>> listFirst() {
        List<RegionListedVo> list = iRegionService.listFirst();
        return AjaxResult.success(list);
    }
    @NotLogin
    @GetMapping("/listByParentId")
    @ApiOperation(value="获取下级地区")
    public AjaxResult<List<RegionListedVo>> listByParentId(@Validated @RequestParam("parentId") Long parentId) {
        List<RegionListedVo> list = iRegionService.listByParentId(parentId);
        return AjaxResult.success(list);
    }
}
